# try-except语句，try如果发生错误，就执行except

# try:
#     # print(1/0)
#     print(2/2)
# except:
#     print("error")


# 捕获指定异常
# try:
#     print(name)
#     # 1 / 0 # 不是NameError的异常，所以不会进入except
# except NameError as e: # e存储异常的信息
#     print("出现异常")
#     print(e)



# 捕获多个异常
# try:
#     # print(name)
#     1 / 0
# except (NameError, ZeroDivisionError) as e:
#     print("出现异常")
#     print(e)




# 捕获所有的异常，直接写except也可以
# try:
#     # print(1/0)
#     print(name)
# except Exception as e:
#     print(e)



# 异常else
# try:
#     print(1)
# except:
#     print("err")
# else:
#     print("ok")










# 模块的导入

# import time # 导入内置的time模块
#
# print("睡一会")
# time.sleep(3) # 需要写time.使用
# print("hello")



# 只导入sleep函数

# from time import sleep
#
# print("睡一会")
# sleep(3) # 不需要写time.
# print("hello")



# 导入全部功能，可以不用写time.
# from time import *
#
# print("睡一会")
# sleep(3)
# print("hello")



# as定义别名


# import time as t
#
# print("睡一会")
# t.sleep(3)
# print("hello")



# from time import sleep as sl
#
# print("睡一会")
# sl(3)
# print("hello")









# 自定义模块

# import my_module1
#
# ret = my_module1.Add(1,2)
# print(ret)


# from my_module1 import Add
#
# ret = Add(1,2)
# print(ret)



# __main__的应用

# from my_module1 import Add # 在my_module文件中没有用到__main__时，会运行该文件中的调用



# __all__变量

# from my_module2 import *
# test1()
# test2()







